package com.eqxiu.ieditor.weixin.util;

import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SignUtils {
	private static Logger logger = LoggerFactory.getLogger(SignUtils.class.getName());

	public static String getSign(Map<String, Object> kv, String secret) throws Exception {
		Set<String> keySet = kv.keySet();
		String encodeString = null;
		StringBuilder buf = new StringBuilder();
		for (String key : keySet) {
			String value = (String) kv.get(key);
			buf.append(key).append('=').append(value).append('&');
		}
		if (secret != null) {
			buf.append("key=").append(secret);
		} else {
			buf.delete(buf.length() - 1, buf.length());
		}
		encodeString = buf.toString();
		logger.info("getSign ::  {}", encodeString);
		return WXPayUtil.MD5(encodeString).toUpperCase();
	}
}
